package bb.lanxing.activity.mine

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import bb.lanxing.App
import bb.lanxing.R
import bb.lanxing.activity.UserCardActivity
import bb.lanxing.activity.base.BaseActivity
import bb.lanxing.activity.login.LogoutDirectionActivity
import bb.lanxing.activity.login.PhoneBindActivity
import bb.lanxing.common.config.Constants.AUTHCODE_TYPE_BICI_FIND_PASSWORD
import bb.lanxing.common.config.Constants.AUTHCODE_TYPE_SET_PASSWORD
import bb.lanxing.common.config.Constants.AUTHCODE_TYPE_UNBIND_BICI
import bb.lanxing.common.config.Constants.REQUEST_CODE
import bb.lanxing.common.config.UmengEventConst
import bb.lanxing.lib.devices.base.DeviceContext
import bb.lanxing.lib.devices.core.utils.DeviceHelper
import bb.lanxing.lib.devices.sprint.entity.SettingSupports
import bb.lanxing.manager.LevelPermissionMgr
import bb.lanxing.manager.RemoteServiceManager
import bb.lanxing.manager.SharedManager
import bb.lanxing.model.bean.LoginModel
import bb.lanxing.model.database.City
import bb.lanxing.model.database.Province
import bb.lanxing.model.database.User
import bb.lanxing.mvp.presetner.ClubPresenter
import bb.lanxing.network.BiCiCallback
import bb.lanxing.network.MyHttpClient
import bb.lanxing.util.BusProvider
import bb.lanxing.util.CommonUtil
import bb.lanxing.util.JsonUtil
import bb.lanxing.util.Log
import bb.lanxing.util.RxPermissionUtil
import bb.lanxing.util.RxPermissionUtil.PermissionCallBack
import bb.lanxing.view.BiciAlertDialogBuilder
import bb.lanxing.view.UserAvatarView
import com.tencent.tauth.Tencent
import com.umeng.analytics.MobclickAgent
import com.umeng.socialize.UMAuthListener
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import org.json.JSONException
import org.json.JSONObject

class UserInfoActivity : BaseActivity() {
    private lateinit var avatarView: UserAvatarView
    private var cityView: TextView? = null
    private var emailView: TextView? = null
    private lateinit var mCompetitionContainer: View
    private var mEmailContainer: View? = null
    private lateinit var mPasswordContainer: View
    private lateinit var mPhoneContainer: View
    private var mQqBtn: View? = null
    private var mRlLevelDetail: View? = null
    private lateinit var mRlLogout: View
    private lateinit var mSignoutBtn: View
    private lateinit var mUserContainer: View
    private var mWechatBtn: View? = null
    private var mWeiboBtn: View? = null
    private var nicknameView: TextView? = null
    private var openObject: JSONObject? = null
    private var passwordHintView: TextView? = null
    private val phoneContainer: View? = null
    private var phoneView: TextView? = null
    private var qqBtn: Button? = null
    private lateinit var signoutBtn: TextView

    //            IWorkoutSyncModel syncModel;
    private var toolbar: Toolbar? = null
    private lateinit var userMy: User
    private var wechatBtn: Button? = null
    private var weiboBtn: Button? = null
    override fun onCreate(bundle: Bundle?) {
        super.onCreate(bundle)
        setContentView(R.layout.activity_user_info)
        bindView(window.decorView)
        setupActionBar(true)
        initView()
    }

    private fun initView() {
        setTitle(R.string.mine_title_profile)
        if (App.getContext().isUserSignin()) {
            signoutBtn.visibility = View.VISIBLE
        } else {
            signoutBtn.visibility = View.GONE
        }
    }

    override fun onResume() {
        super.onResume()
        loadData()
    }

    private fun loadData() {
        val signinUser = App.getContext().signinUser
        userMy = signinUser
        if (signinUser == null) {
            finish()
            return
        }
        //        syncModel = new WorkoutSyncModelImpl();
        avatarView.setAvatarMode(UserAvatarView.AVATAR_SIZE_48)
        avatarView.setAvatarForUrl(userMy.photoUrl)
        avatarView.setUserLevelText(userMy.level)
        avatarView.enableAvatarBorder()
        if (userMy.proName != null && userMy.proName.isNotEmpty()) {
            avatarView.isShowAvatarFrame(true)
            avatarView.setProTitle(userMy.proName)
        } else {
            avatarView.isShowAvatarFrame(false)
            avatarView.setProTitle(null)
        }
        nicknameView!!.text = userMy.name
        var str = ""
        if (!TextUtils.isEmpty(userMy.province) && !CommonUtil.isCityCountOne(
                userMy.province
            )
        ) {
            str = userMy.province + " "
        }
        if (!TextUtils.isEmpty(userMy.city)) {
            str = str + userMy.city
        }
        if (TextUtils.isEmpty(str)) {
            cityView!!.setText(R.string.value_not_setting)
        } else {
            cityView!!.text = str
        }
        val phone = userMy.phone
        if (TextUtils.isEmpty(phone)) {
            phoneView!!.setText(R.string.mine_profile_desc_bind_phone)
        } else {
            phoneView!!.text = phone
        }
        if (userMy.havePassword == 0) {
            passwordHintView!!.setText(R.string.mine_profile_desc_set_password)
        } else {
            passwordHintView!!.setText(R.string.mine_profile_desc_change_password)
        }
        initThirdParty()
    }

    private fun initThirdParty() {
        if (TextUtils.isEmpty(userMy.qq)) {
            qqBtn!!.setText(R.string.mine_profile_label_3rd_unbind)
            qqBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                null, getResources().getDrawable(R.drawable.ic_qq), null, null
            )
        } else {
            qqBtn!!.text = userMy.qq
            qqBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                null, getResources().getDrawable(R.drawable.ic_qq_binding), null, null
            )
        }
        if (TextUtils.isEmpty(userMy.wechat)) {
            wechatBtn!!.setText(R.string.mine_profile_label_3rd_unbind)
            wechatBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                null, getResources().getDrawable(R.drawable.ic_wechat), null, null
            )
        } else {
            wechatBtn!!.text = userMy.wechat
            wechatBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                null, getResources().getDrawable(R.drawable.ic_wechat_binding), null, null
            )
        }
        if (TextUtils.isEmpty(userMy.weibo)) {
            weiboBtn!!.setText(R.string.mine_profile_label_3rd_unbind)
            weiboBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                null, getResources().getDrawable(R.drawable.ic_weibo), null, null
            )
        } else {
            weiboBtn!!.text = userMy.weibo
            weiboBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                null, getResources().getDrawable(R.drawable.ic_weibo_binding), null, null
            )
        }
    }

    fun onUserClick(view: View) {
        MobclickAgent.onEventValue(this, UmengEventConst.MINE_INFO_PROFILE, null, 1)
        startActivity(Intent(this, ProfileEditActivity::class.java))
    }

    fun onCompetitionClick(view: View) {
        if (!App.getContext().isUserSignin()) {
            App.getContext().userSignin()
            return
        }
        MobclickAgent.onEventValue(this, UmengEventConst.MINE_INFO_CARD_ENTRY, null, 1)
        startActivity(Intent(this, UserCardActivity::class.java))
    }

    fun onPhoneClick(view: View) {
        if (TextUtils.isEmpty(userMy.phone)) {
            val intent = Intent(this, PhoneBindActivity::class.java)
            intent.putExtra("user_id", userMy.uid)
            intent.putExtra(
                "type",
                if (userMy.havePassword == 0) AUTHCODE_TYPE_BICI_FIND_PASSWORD else AUTHCODE_TYPE_UNBIND_BICI
            )
            startActivityForResult(intent, REQUEST_CODE)
            return
        }
//        showUnbindPhoneDialog()
    }

    fun onLogOutClick(view: View) {
        startActivity(Intent(this, LogoutDirectionActivity::class.java))
    }

    fun signOutClick(view: View) {
        MobclickAgent.onEventValue(this, "my_signout", null, 1)
        if (RemoteServiceManager.getInstance().isSporting) {
            App.getContext().showMessage(R.string.mine_history_toast_stop_sport_first)
        } else {
//            syncModel.getUnUploadWorkout(SharedManager.getInstance().getUserId(), new AnonymousClass1());
            showSignOutDialog()
        }
    }

    private fun showStoragePermissionDialog() {
        BiciAlertDialogBuilder(this).setTitle(getString(R.string.permission_request_permission_tips))
            .setMessage(getResources().getString(R.string.permission_user_level_need_storage))
            .setCancelable(true).setPositiveButton(R.string.dialog_btn_ok) { _, _ ->
                requestStoragePermission()
            }.setNegativeButton(R.string.skip) { _, _ -> }.show()
    }

    private fun requestStoragePermission() {
        RxPermissionUtil.getInstance().setPermissions(*RxPermissionUtil.getStoragePermissions())
            .permissionRequestEachCombined(this, object : PermissionCallBack {
                override fun deny() {}
                override fun granted() {
                    if (!App.isManagersInit) {
                        App.getContext().initManagersWithPermissions()
                    } else {
                        LevelPermissionMgr.getInstance().init()
                    }
                }
            })
    }

    private fun bindPhone() {
        activity.startActivity(
            Intent(activity, PhoneBindActivity::class.java).putExtra(
                "user_id", App.getContext().signinUser.uid
            ).putExtra("canBack", false)
        )
        intent.putExtra(
            "type",
            if (userMy.havePassword == 0) AUTHCODE_TYPE_BICI_FIND_PASSWORD else AUTHCODE_TYPE_UNBIND_BICI
        )

    }

    private fun changePassword(view: View) {
        activity.startActivity(
            Intent(activity, PhoneBindActivity::class.java).putExtra(
                "user_id", App.getContext().signinUser.uid
            ).putExtra("type", AUTHCODE_TYPE_SET_PASSWORD)
        )
    }

    private fun unbindPhone(z: Boolean) {
        BiciAlertDialogBuilder(this).setTitle(R.string.st_tip)
            .setMessage(R.string.st_des_unbind_phone).setPositiveButton(
                R.string.st_action_unbind_phone
            ) { _, _ ->
                if (z) {
                    unbindAccount(1)
                    return@setPositiveButton
                }
            }.setNeutralButton(R.string.dialog_btn_cancel) { _, _ -> }.show()
    }

    private fun changePhoneNum() {
        val intent = Intent(this, PhoneBindActivity::class.java)
        intent.putExtra("user_id", userMy.uid)
        intent.putExtra(
            "type",
            if (userMy.havePassword == 0) AUTHCODE_TYPE_BICI_FIND_PASSWORD else AUTHCODE_TYPE_UNBIND_BICI
        )
        startActivityForResult(intent, REQUEST_CODE)
    }

    private fun unbindAccount(i: Int) {
        MyHttpClient.unbindAccount(object : BiCiCallback(this) {
            @Throws(JSONException::class)
            override fun onResponseString(str: String) {
                App.getContext().showMessage(R.string.mine_profile_toast_unbind_successful)
                if (i == ACCOUNT_TYPE_PHONE) {
                    userMy.phone = null
                    userMy.save()
                    runOnUiThread {
                        phoneView!!.setText(R.string.mine_profile_desc_bind_phone)
                        signOut()
                    }
                } else if (i == ACCOUNT_TYPE_EMAIL) {
                    userMy.email = null
                    userMy.save()
                    runOnUiThread {
                        emailView!!.setText(
                            R.string.mine_profile_desc_bind_email
                        )
                    }
                }
            }
        }, i)
    }

    private fun signOut() {
        MyHttpClient.signout()
        App.getContext().cleanSigninState()
        //        App.getContext().stopRemoteService(WorkoutRemoteService.class);
        App.getContext().showMessage(R.string.mine_profile_toast_logout_successful)
        signoutBtn.visibility = View.GONE
        sendMessage(R.id.msg_user_logout)
        DeviceContext.stopAutoConnector()
        DeviceHelper.disconnectAll()
        ClubPresenter.postClubEvent(13, 0L, null)
        BusProvider.getInstance().post(LoginModel(true))
        finish()
    }

    //    public void showSignoutDialog() {
    //        new BiciAlertDialogBuilder(this).setTitle(R.string.mine_profile_dialog_title_logout).setMessage(R.string.mine_profile_dialog_content_logout)
    //        .setPositiveButton(R.string.mine_profile_dialog_btn_do_logout, new DialogInterface.OnClickListener() {
    //            @Override
    //            public void onClick(DialogInterface dialogInterface, int i) {
    //                signout();
    //            }
    //        }).setNegativeButton(R.string.mine_profile_dialog_btn_not_logout, (dialogInterface, i) -> {
    //        }).show().setCanceledOnTouchOutside(true);
    //    }
    override fun onActivityResult(i: Int, i2: Int, intent: Intent?) {
        super.onActivityResult(i, i2, intent)
        UMShareAPI.get(this).onActivityResult(i, i2, intent)
        if (i2 == -1 && i == REQUEST_CODE && intent != null) {
            val stringExtra = intent.getStringExtra("phoneNumber")
            if (!TextUtils.isEmpty(stringExtra)) {
                phoneView!!.text = stringExtra
            }
            val stringExtra2 = intent.getStringExtra("email")
            if (TextUtils.isEmpty(stringExtra2)) {
                return
            }
            emailView!!.text = stringExtra2
        }
    }

    private fun umDoOauthVerify(share_media: SHARE_MEDIA) {
        if (share_media != SHARE_MEDIA.SINA) {
            showMyProgressDialog()
        }
        if (Province.getCount() <= 0) {
            Province.importDatas()
            City.importDatas()
        }
        openObject = JSONObject()
        Tencent.setIsPermissionGranted(true)
        UMShareAPI.get(this).doOauthVerify(this, share_media, object : UMAuthListener {
            override fun onStart(share_media2: SHARE_MEDIA) {
                Log.d("umDoOauthVerify onStart $share_media2")
            }

            override fun onComplete(share_media2: SHARE_MEDIA, i: Int, map: Map<String, String>) {
                val str: String?
                Log.d("umDoOauthVerify onComplete $share_media2 , $map")
                if (share_media2 == SHARE_MEDIA.WEIXIN || !TextUtils.isEmpty(
                        map["uid"]
                    )
                ) {
                    try {
                        var str2: String? = null
                        var i2 = TYPE_QQ
                        if (share_media == SHARE_MEDIA.QQ) {
                            str2 = map["access_token"]
                            str = map["openid"]
                        } else if (share_media == SHARE_MEDIA.WEIXIN) {
                            i2 = TYPE_WECHAT
                            str2 = map["access_token"]
                            str = map["openid"]
                        } else if (share_media == SHARE_MEDIA.SINA) {
                            i2 = TYPE_WEIBO
                            var str3 = map["access_key"]
                            if (TextUtils.isEmpty(str3)) {
                                str3 = map["access_token"]
                            }
                            str2 = str3
                            str = map["uid"]
                        } else {
                            str = null
                        }
                        openObject!!.put("ltype", i2)
                        openObject!!.put("access_token", str2)
                        openObject!!.put(
                            com.tencent.connect.common.Constants.JumpUrlConstants.URL_KEY_OPENID,
                            str
                        )
                        getPlatformInfo(share_media)
                        return
                    } catch (e: Exception) {
                        App.getContext().showMessage(R.string.mine_profile_toast_3rd_parse_failed)
                        e.printStackTrace()
                        dismissLoadingDialog()
                        return
                    }
                }
                App.getContext().showMessage(R.string.mine_profile_toast_3rd_auth_failed)
                dismissLoadingDialog()
            }

            override fun onError(share_media2: SHARE_MEDIA, i: Int, th: Throwable) {
                Log.d("umDoOauthVerify onError $share_media2 , $th")
                App.getContext().showMessage(R.string.mine_profile_toast_3rd_auth_failed)
                dismissLoadingDialog()
            }

            override fun onCancel(share_media2: SHARE_MEDIA, i: Int) {
                Log.d("umDoOauthVerify onCancel $share_media2")
                dismissLoadingDialog()
            }
        })
    }

    fun getPlatformInfo(share_media: SHARE_MEDIA) {
        UMShareAPI.get(this).getPlatformInfo(this, share_media, object : UMAuthListener {
            override fun onStart(share_media2: SHARE_MEDIA) {
                Log.i("umDoOauthVerify", "onStart $share_media2")
            }

            override fun onComplete(share_media2: SHARE_MEDIA, i: Int, map: Map<String, String>) {
                val str: String?
                val str2: String?
                val str3: String?
                val str4: String?
                val z: Boolean
                var i2 = TYPE_QQ
                var i3 = false
                Log.i("auth", "status = $i")
                try {
                    var i4 = 0
                    var i5 = 1
                    var str5: String? = null
                    if (share_media == SHARE_MEDIA.QQ) {
                        str = map["screen_name"]
                        str2 = map["profile_image_url"]
                        str3 = map["city"]
                        str4 = map["province"]
                        z = "男" == map[SettingSupports.SUPPORT_ITEM_GENDER]
                    } else {
                        if (share_media == SHARE_MEDIA.WEIXIN) {
                            str5 = map["unionid"]
                            str = map["screen_name"]
                            str2 = map["profile_image_url"]
                            str3 = map["city"]
                            str4 = map["province"]
                            i2 = TYPE_WECHAT
                            i3 = "男" == map[SettingSupports.SUPPORT_ITEM_GENDER]
                        } else if (share_media == SHARE_MEDIA.SINA) {
                            str = map["screen_name"]
                            str2 = map["profile_image_url"]
                            str3 = map["location"]
                            i2 = TYPE_WEIBO
                            str4 = null
                            i3 = "男" == map[SettingSupports.SUPPORT_ITEM_GENDER]
                        } else {
                            str = null
                            str2 = null
                            str3 = null
                            str4 = null
                            z = true
                        }
                        if (!TextUtils.isEmpty(str5)) {
                            openObject!!.put("union_id", str5)
                        }
                        openObject!!.put("avatar", str2)
                        openObject!!.put("nick_name", str)
                        if (!TextUtils.isEmpty(str3) && City.getCityIdByName(str3)
                                .also { i4 = it } == 0
                        ) {
                            i4 = City.getCityIdByName(str4)
                        }
                        val jSONObject = openObject
                        if (i4 == 0) {
                            i5 = i4
                        }
                        jSONObject!!.put("city_id", i5)
                        openObject!!.put(SettingSupports.SUPPORT_ITEM_GENDER, i3)
                        val userInfoActivity = this@UserInfoActivity
                        bindThirdParty(i2, openObject)
                        return
                    }
                    i2 = TYPE_QQ
                    i3 = z
                    openObject!!.put("avatar", str2)
                    openObject!!.put("nick_name", str)
                    if (!TextUtils.isEmpty(str3)) {
                        i4 = City.getCityIdByName(str3)
                    }
                    val jSONObject2 = openObject
                    jSONObject2!!.put("city_id", i5)
                    openObject!!.put(SettingSupports.SUPPORT_ITEM_GENDER, i3)
                    bindThirdParty(i2, openObject)
                    return
                } catch (e: Exception) {
                    App.getContext().showMessage(R.string.mine_profile_toast_3rd_request_failed)
                    e.printStackTrace()
                    dismissLoadingDialog()
                    return
                }
                App.getContext().showMessage(R.string.mine_profile_toast_3rd_request_failed)
                dismissLoadingDialog()
            }

            override fun onError(share_media2: SHARE_MEDIA, i: Int, th: Throwable) {
                Log.e("umDoOauthVerify", "onError $share_media2 , $th")
            }

            override fun onCancel(share_media2: SHARE_MEDIA, i: Int) {
                Log.i("umDoOauthVerify", "onCancel $share_media2")
            }
        })
    }

    fun bindThirdParty(i: Int, jSONObject: JSONObject?) {
        MyHttpClient.bindThirdParty(object : BiCiCallback(this) {
            override fun onResponseString(str: String) {
                App.getContext().showMessage(R.string.mine_profile_toast_bind_successful)
                runOnUiThread { bindSuccess(i, jSONObject) }
            }
        }, jSONObject)
    }

    private fun unbindThirdParty(i: Int) {
        showMyProgressDialog()
        MyHttpClient.unbindThirdParty(object : BiCiCallback(this) {
            override fun onResponseString(str: String) {
                App.getContext().showMessage(R.string.mine_profile_toast_unbind_successful)
                runOnUiThread { onUnbindSuccess(i) }
            }
        }, i)
    }

    fun bindSuccess(i: Int, jSONObject: JSONObject?) {
        val stringValue = JsonUtil.getStringValue(
            com.tencent.connect.common.Constants.JumpUrlConstants.URL_KEY_OPENID, jSONObject
        )
        val token = JsonUtil.getStringValue("access_token", jSONObject)
        val nickname = JsonUtil.getStringValue("nick_name", jSONObject)
//        val thirdPartPartyToken =
//            CommonUtil.encodeThirtPartyToken(stringValue, token, nickname)
        when (i) {
            0 -> {
                MobclickAgent.onEventValue(this, UmengEventConst.MINE_INFO_BIND_QQ, null, 1)
                val button = qqBtn
                button!!.text = nickname
                qqBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                    null, getResources().getDrawable(R.drawable.ic_qq_binding), null, null
                )
                userMy.qq = nickname
                SharedManager.getInstance().isSyncQQHealth = true
            }

            1 -> {
                MobclickAgent.onEventValue(this, UmengEventConst.MINE_INFO_BIND_WECHAT, null, 1)
                val button2 = wechatBtn
                button2!!.text = nickname
                wechatBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                    null, getResources().getDrawable(R.drawable.ic_wechat_binding), null, null
                )
                userMy.wechat = nickname
            }

            2 -> {
                MobclickAgent.onEventValue(this, UmengEventConst.MINE_INFO_BIND_WEIBO, null, 1)
                val button3 = weiboBtn
                button3!!.text = nickname
                weiboBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                    null, getResources().getDrawable(R.drawable.ic_weibo_binding), null, null
                )
                userMy.weibo = nickname
            }
        }
        userMy.save()
    }

    private fun onUnbindSuccess(i: Int) {
        when (i) {
            0 -> {
                qqBtn!!.setText(R.string.mine_profile_label_3rd_unbind)
                qqBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                    null, getResources().getDrawable(R.drawable.ic_qq), null, null
                )
                userMy.qq = ""
            }

            1 -> {
                wechatBtn!!.setText(R.string.mine_profile_label_3rd_unbind)
                wechatBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                    null, getResources().getDrawable(R.drawable.ic_wechat), null, null
                )
                userMy.wechat = ""
            }

            2 -> {
                weiboBtn!!.setText(R.string.mine_profile_label_3rd_unbind)
                weiboBtn!!.setCompoundDrawablesWithIntrinsicBounds(
                    null, getResources().getDrawable(R.drawable.ic_weibo), null, null
                )
                userMy.weibo = ""
            }
        }
        userMy.save()
    }

    private fun bindView(view: View) {
        avatarView = view.findViewById(R.id.avatarView)
        nicknameView = view.findViewById(R.id.nicknameView)
        emailView = view.findViewById(R.id.emailView)
        cityView = view.findViewById(R.id.cityView)
        phoneView = view.findViewById(R.id.phoneView)
        passwordHintView = view.findViewById(R.id.passwordHintView)
        signoutBtn = view.findViewById(R.id.signoutBtn)
        wechatBtn = view.findViewById(R.id.wechatBtn)
        qqBtn = view.findViewById(R.id.qqBtn)
        weiboBtn = view.findViewById(R.id.weiboBtn)
        toolbar = view.findViewById(R.id.toolbar)
        mUserContainer = view.findViewById(R.id.userContainer)
        mCompetitionContainer = view.findViewById(R.id.competitionContainer)
        mRlLevelDetail = view.findViewById(R.id.rl_level_detail)
        mPhoneContainer = view.findViewById(R.id.phoneContainer)
        mEmailContainer = view.findViewById(R.id.emailContainer)
        mPasswordContainer = view.findViewById(R.id.passwordContainer)
        mRlLogout = view.findViewById(R.id.rl_logout)
        mSignoutBtn = view.findViewById(R.id.signoutBtn)
        mQqBtn = view.findViewById(R.id.qqBtn)
        mWechatBtn = view.findViewById(R.id.wechatBtn)
        mWeiboBtn = view.findViewById(R.id.weiboBtn)
        mUserContainer.setOnClickListener(this::onUserClick)
        mCompetitionContainer.setOnClickListener(this::onCompetitionClick)
//        mRlLevelDetail.setOnClickListener();
        mPhoneContainer.setOnClickListener(this::onPhoneClick)
        mPasswordContainer.setOnClickListener(this::changePassword)
        mRlLogout.setOnClickListener(this::onLogOutClick)
        mSignoutBtn.setOnClickListener(this::signOutClick)
        mQqBtn!!.setOnClickListener(this::thirdPartyHandle)
        mWeiboBtn!!.setOnClickListener(this::thirdPartyHandle)
        mWechatBtn!!.setOnClickListener(this::thirdPartyHandle)

//        mWechatBtn.setOnClickListener();
//        mWeiboBtn.setOnClickListener();
    }

    private fun showSignOutDialog() {
        BiciAlertDialogBuilder(this).setTitle(R.string.mine_profile_dialog_title_logout)
            .setMessage(R.string.mine_profile_dialog_content_logout)
            .setPositiveButton(R.string.mine_profile_dialog_btn_do_logout) { _, _ -> signOut() }
            .setNegativeButton(R.string.mine_profile_dialog_btn_not_logout) { _, _ -> }.show()
            .setCanceledOnTouchOutside(true)
    }

    fun thirdPartyHandle(view: View) {
        val id = view.id
        if (id == R.id.qqBtn) {
            if (TextUtils.isEmpty(userMy.qq)) {
                umDoOauthVerify(SHARE_MEDIA.QQ)
            } else {
                unbindThirdParty(TYPE_QQ)
            }
        } else if (id == R.id.wechatBtn) {
            if (TextUtils.isEmpty(userMy.wechat)) {
                umDoOauthVerify(SHARE_MEDIA.WEIXIN)
            } else {
                unbindThirdParty(TYPE_WECHAT)
            }
        } else if (id != R.id.weiboBtn) {
        } else {
            if (TextUtils.isEmpty(userMy.weibo)) {
                umDoOauthVerify(SHARE_MEDIA.SINA)
            } else {
                unbindThirdParty(TYPE_WEIBO)
            }
        }
    }

    companion object {
        const val ACCOUNT_TYPE_EMAIL = 2
        const val ACCOUNT_TYPE_PHONE = 1
        const val TYPE_QQ = 0
        const val TYPE_WECHAT = 1
        const val TYPE_WEIBO = 2
    }
}